home *** CD-ROM | disk | FTP | other *** search
- (*********************************************************************
- *
- * PROGRAM NAME: PLAYVOCM.PAS
- *
- * COMPILER: Borland Turbo Pascal ver. 4 or later
- *
- * DESCRIPTION: Plays a .VOC file from the conventional memory using
- * the CT-VOICE.DRV driver (accessed from SBSIM). To run
- * the program, type the following at the command line:
- *
- * PLAYVOCM FILENAME
- *
- * Where FILENAME is the drive/path/filename of the .VOC
- * file to play.
- *
- * NOTE: SBSIM driver must be loaded before running this program.
- *
- * WARNING: This program does NOT support files larger than 64KB!
- *
- *********************************************************************)
-
- program playvocm;
- uses dos,crt;
-
- const HEADER_OFFSET = $1A;
- const VOC_MEM_DRIVER = $04;
-
-
- {$I drvrfunc.pas}
-
- var Command:char;
- UserQuit:boolean;
- RetValue:simerr;
- FileName:string;
- FileHandle:integer;
- F:file;
- FSize :longint;
- Buffer:^byte;
-
-
- (********************************************************************)
- begin (* main *)
-
- if paramcount <> 1 (* no. of parameters entered on command line *)
- then begin
- writeln('Command line must contain EXACTLY ONE filename parameter!');
- halt; (* Terminate program *)
- end;
-
- (*--- SEE IF SBSIM DRIVER HAS LOADED --*)
- SIMint := FindDvr('SBSIM', $0103); (* Get SBSIM's interrupt no. *)
- if SIMint = 0
- then begin
- writeln('SBSIM driver not loaded!');
- halt; (* Terminate program *)
- end;
-
- (*--- SEE IF CT-VOICE.DRV DRIVER HAS LOADED -------*)
- if (GetDrvrs and VOC_MEM_DRIVER) <> VOC_MEM_DRIVER
- then begin
- writeln('CT-VOICE.DRV not loaded!');
- halt; (* Terminate program *)
- end;
-
-
- (*--- OPEN FILE SPECIFIED ON COMMAND LINE ------*)
- FileHandle := DosOpen(paramstr(1), ReadAccess);
- if (FileHandle = -1)
- then begin
- writeln('FILE: ',paramstr(1), ' not successfully opened!');
- halt; (* Terminate program *)
- end;
-
- DosClose(FileHandle);
-
- FileName:=paramstr(1); (* copy to string with more space before modifying *)
- assign(F,Filename);
- reset(F,1);
-
- (*--- GET THE FILE SIZE -------------------------*)
- Fsize := filesize(F);
- if Fsize > 65535
- then begin
- writeln('File size > 64KB not supported!');
- halt; (* Terminate program *)
- end;
-
- seek(F, HEADER_OFFSET);
-
- (*--- ALLOCATE BUFFER AND LOAD IT FROM FILE -----------*)
- getmem(Buffer, Fsize-HEADER_OFFSET);
- if Buffer = nil
- (*& **** if ((Buffer = (char * ) malloc((size_t) Fsize)) == NULL) ******)
- then begin
- writeln('Memory buffer not allocated!');
- halt; (* Terminate program *)
- end;
-
- (* Read the file, without header, into memory. *)
- blockread(F, Buffer^, Fsize-HEADER_OFFSET);
- close(F); (* Done with the file, close it! *)
-
-
- (*--- StartSnd() INITIALIZES THE CT-VOICE DRIVER -----------*)
- RetValue := StartSnd(MemVoice, Buffer, false, 0);
- if RetValue <> SIMerr_NoErr
- then begin
- writeln('ERROR CALLING SBSIM: ', errorMsg[RetValue]);
- freemem(Buffer, Fsize-HEADER_OFFSET); (* Deallocate memory *)
- halt; (* Terminate program *)
- end;
-
- (*--- PlaySnd() BEGINS PLAYING OF THE FILE ----------*)
- RetValue := PlaySnd(MemVoice);
- if RetValue <> SIMerr_NoErr
- then begin
- writeln('ERROR CALLING SBSIM: ', errorMsg[RetValue]);
- freemem(Buffer, Fsize-HEADER_OFFSET); (* Deallocate memory *)
- halt; (* Terminate program *)
- end;
-
- clrscr; (* Clear screen *)
- writeln(#10#10#10#10#10' SELECT ONE OF THE FOLLOWING OR WAIT UNTIL DONE:');
- writeln(' (P)ause');
- writeln(' (R)esume');
- writeln(' (Q)uit');
-
- UserQuit := false;
-
- (*--- PROCESS USER INTERACTION OR WAIT FOR SOUND TO STOP -----------*)
- repeat
- if (keypressed) (* Was a key pressed? *)
- then begin
- Command := upcase(readkey); (* Get char that's in buffer *)
- if Command = 'P'
- then PauseSnd(MemVoice)
- else if Command = 'R'
- then ResumeSnd(MemVoice)
- else if Command = 'Q'
- then UserQuit := true;
- end;
- (* Exit do-while loop if file is done playing or user typed 'Q' *)
- until (UserQuit = true) or (GetSndStat(MemVoice) = 0);
-
- (*--- IF SOUND IS STILL PLAYING AND USER HIT 'Q', STOP THE SOUND ---*)
- if (GetSndStat(MemVoice) <> 0) and (UserQuit = true)
- then StopSnd(MemVoice);
-
- freemem(Buffer, Fsize-HEADER_OFFSET); (* Deallocate memory *)
-
- end.